require(['./config'],()=>{
    require(['jquery','header','utils'],(jquery)=>{
        class Login{
            constructor(){
                this.init()
             
            }
            init(){
               $('#submit').on('click',()=>{
                   const username = $('.username').val()
                   const password = $('.password').val()
                   let users = localStorage.getItem('users')//取
                    if(users){
                    // 如果有就转为数组
                    users = JSON.parse(users) 
                    //some只要瞒住一个条件就返回布尔值，并且不会返回新数组
                    const isExist = users.some(user =>{
                        return user.username === username && user.password === password
                    })
                    console.log(isExist);
                    
                     
                     if(isExist){
                         utils.setCookie('log',username,{expires: 7, path: '/'})  //這個就是存cookie 
                   
                        alert('登录成功，即将跳转页面')
                        window.location.href='/index.html'
                    }else{
                        alert("用户密码错误")
                    }

                    }else{
                        alert("登录去")
                    }
                   
               })
            
                
            }
          
        }
        new Login
    })
})